﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace PortalWeb.Core.IDao
{
    public partial interface IBaseRepository<T> : IDisposable
    {
        /// <summary>
        /// 查找对象
        /// </summary>
        /// <returns></returns>
        T Find(dynamic primaryId);

        /// <summary>
        ///  实现对数据库的查询  --简单查询
        /// </summary>
        /// <returns></returns>
        IEnumerable<T> Find(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        long Add(T entity);

        int Count();

        /// <summary>
        /// 更新
        /// </summary>
        /// <returns></returns>
        bool Update(T entity, bool isSave = true);



        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entityList"></param>
        /// <param name="isSave"></param>
        /// <returns></returns>
        bool Delete(IList<T> entityList, bool isSave = true);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="isSave"></param>
        /// <returns></returns>
        bool Delete(T entity, bool isSave = true);

        /// <summary>
        /// 统计数量
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        int Count(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="anyLambda"></param>
        /// <returns></returns>
        bool Exist(Expression<Func<T, bool>> anyLambda);

        T[] LoadPageEntities<TS>(Expression<Func<T, bool>> whereLambda, bool isAsc,
            Expression<Func<T, TS>> orderByLambda, int offset, int limit);

        T[] LoadPageEntities(Expression<Func<T, bool>> whereLambda, string order, string sort, int offset, int limit);

    }
}
